use "$raw/s4_to_s5_noPII.dta", clear
merge 1:1 id using "$cleaned/all_s4_cleaned.dta"

**************************************
*	Table A14
**************************************
replace S5=0 if S5==.
reg S5 treatment school* std_AGG_mock, robust
sum S5 if treatment==0
local mean=r(mean)
outreg2 using "${output}/Table_A14.tex", dec(2) title(Impact of treatment assignment on continuing to upper secondary school) keep(S5 treatment) addstat(Mean control, `mean') adec(2) replace
reg S5 treatment school* AGE female subject_count std_AGG_mock, robust
sum S5 if treatment==0
local mean=r(mean)
outreg2 using "${output}/Table_A14.tex", dec(2) title(Impact of treatment assignment on continuing to upper secondary school) keep(S5 treatment AGE female subject_count std_AGG_mock) addstat(Mean control, `mean') adec(2)

local subgroup female   below_median_mock
foreach x of local subgroup { 
gen treatment_`x'=treatment*`x'
reg S5 treatment treatment_`x' `x' ${controls} std_AGG_mock school* , robust
test `x' + treatment_`x' + treatment = `x'
lincom treatment_`x' + treatment
local F1c = r(estimate)
local F1se = r(se)
test `x' + treatment_`x' + treatment = `x'
local p_value = r(p)
sum S5 if treatment==0 & `x'==1
local mean=r(mean)
outreg2 using "${output}/Table_A14.tex", dec(2) title(Impact of treatment assignment on continuing to upper secondary school) keep(S5 treatment treatment_`x' `x' ${controls} ) adec(2) addstat(treated, `F1c',SE , `F1se', p_value, `p_value', Mean control, `mean') 
}

